<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>菜单管理</title>
	<meta name="decorator" content="default"/>
	<%@include file="/WEB-INF/views/include/treetable.jsp" %>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#treeTable").treeTable({expandLevel : 3}).show();
			layui.use(['laypage', 'form'], function(){
				form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
				form.render();
			});
// 			var table = layui.table;
// 			table.init('menuTable');
// 			var tableBody = $(".layui-table-main").children(".layui-table");
// 			$(tableBody[0]).treeTable({expandLevel : 3}).show();
			
		});
    	function updateSort() {
			loading('正在提交，请稍等...');
	    	$("#listForm").attr("action", "${ctx}/sys/menu/updateSort");
	    	$("#listForm").submit();
    	}
	</script>
</head>
<body>
	<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
		<ul class="layui-tab-title">
		<li class="layui-this"><a href="${ctx}/sys/menu/">菜单列表</a></li>
		<shiro:hasPermission name="sys:menu:edit"><li><a href="${ctx}/sys/menu/form">菜单添加</a></li></shiro:hasPermission>
	</ul></div>
	<sys:message content="${message}"/>
	<form id="listForm" method="post">
		<div class="layui-form layui-border-box layui-table-view">
		<div class="layui-table-body layui-table-main">
		<table id="treeTable" class="layui-table " lay-filter="menuTable" lay-data="{class:'tree_table'}">
			<thead>
				<tr>
					<th lay-data="{field:'name', minWidth:200}" style="width:200px">
						<div class="layui-table-cell">名称</div>
					</th>
					<th lay-data="{field:'link', minWidth:50}" style="width:100px">
						<div class="layui-table-cell" >链接</div>
					</th>
					<th style="text-align:center;width:50px" lay-data="{field:'sort', minWidth:50}">
						<div class="layui-table-cell">排序</div>
					</th>
					<th lay-data="{field:'visibility', minWidth:50}" style="width:50px">
						<div class="layui-table-cell" >可见</div>
					</th>
					<th lay-data="{field:'mark', minWidth:50}" style="width:50px">
						<div class="layui-table-cell" >权限标识</div>
					</th>
					<shiro:hasPermission name="sys:menu:edit">
						<th lay-data="{field:'delFlag', minWidth:180}" style="width:180px">
							<div class="layui-table-cell" >操作</div>
						</th>
					</shiro:hasPermission></tr></thead>
			<tbody><c:forEach items="${list}" var="menu">
				<tr id="${menu.id}" pId="${menu.parent.id ne '1'?menu.parent.id:'0'}">
					<td class="layui-table-cell" nowrap>
						<i class="icon-${not empty menu.icon?menu.icon:' hide'}"></i><a class="layui-blue" href="${ctx}/sys/menu/form?id=${menu.id}">${menu.name}</a>
					</td>
					<td title="${menu.href}">
						<div class="layui-table-cell">${fns:abbr(menu.href,30)}</div>
					</td>
					<td style="text-align:center; width:70px;"><div class="layui-table-cell">
						<shiro:hasPermission name="sys:menu:edit">
							<input type="hidden" name="ids" value="${menu.id}"/>
							<input name="sorts" type="text" value="${menu.sort}" style="margin-right:0;padding:0;text-align:center;" class="layui-input" />
						</shiro:hasPermission><shiro:lacksPermission name="sys:menu:edit">
							${menu.sort}
						</shiro:lacksPermission>
					</div></td>
					<td><div class="layui-table-cell">${menu.isShow eq '1'?'显示':'隐藏'}</div></td>
					<td title="${menu.permission}"><div class="layui-table-cell">
						${fns:abbr(menu.permission,30)}
					</div></td>
					<shiro:hasPermission name="sys:menu:edit"><td nowrap><div class="layui-table-cell">
						<a class="layui-btn layui-btn-xs" lay-event="edit"
						 href="${ctx}/sys/menu/form?id=${menu.id}">修改</a>
						<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"
						 href="${ctx}/sys/menu/delete?id=${menu.id}" onclick="return confirmx('要删除该菜单及所有子菜单项吗？', this.href)">删除</a>
						<a class="layui-btn layui-btn-normal layui-btn-xs"
						 href="${ctx}/sys/menu/form?parent.id=${menu.id}">添加下级菜单</a> 
					</div></td></shiro:hasPermission>
				</tr>
			</c:forEach></tbody>
		</table>
		</div></div>
		<shiro:hasPermission name="sys:menu:edit"><div class="form-actions pagination-left">
			<input id="btnSubmit" class="layui-btn" type="button" value="保存排序" onclick="updateSort();"/>
		</div></shiro:hasPermission>
	 </form>
</body>
</html>